package com.synjones.handsetS8.ild.net.api;

import com.google.gson.Gson;
import com.synjones.handsetS8.ild.constants.Headers;
import com.synjones.handsetS8.ild.net.common.NetCallback;
import com.synjones.handsetS8.ild.net.common.NetClient;
import com.synjones.handsetS8.ild.net.model.LoginResult;
import com.synjones.handsetS8.ild.net.model.NetResult;

import java.util.HashMap;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.POST;

public class AccountApi {
    private static final String BASE_URL = "http://jiangong-manager.dev1.i-laodong.com/";
    private static IdCardService service = NetClient.getRetrofit(BASE_URL).create(IdCardService.class);

    /**
     * 登录 接口
     */
    public static void login(String account, String password, NetCallback<NetResult<LoginResult>> callback) {
        Map<String, Object> map = new HashMap<>();
        map.put("app_id", "jg_app_portable");
        map.put("device_id", "4d$");
        map.put("device_type", "andriod");
        map.put("grant_type", "password");
        map.put("username", account);
        map.put("password", password);

        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), new Gson().toJson(map));
        Call<NetResult<LoginResult>> call = service.login("application/json", requestBody);
        call.enqueue(callback);
    }

    interface IdCardService {
        /**
         * 用户名密码登录
         *
         * @return
         */
        @POST("api/auth/login")
        Call<NetResult<LoginResult>> login(@Header(Headers.CONTENT_TYPE) String contentType, @Body RequestBody body);
    }
}
